
//
//  UIBarButtonItem+Item.swift
//  Swift_missScarlett
//
//  Created by xmg on 16/9/19.
//  Copyright © 2016年 wlis. All rights reserved.
//

import UIKit

extension UIBarButtonItem {

    // MARK: - 设置高亮
    class func itemWithCustomView(imageNor: String, imageHigh: String, target: AnyObject?, action: Selector) -> UIBarButtonItem {
        
        let leftButton = UIButton(type:.Custom);
        leftButton.setImage(UIImage(named: imageNor), forState: .Normal)
        leftButton.setImage(UIImage(named: imageHigh), forState: .Highlighted)
        leftButton.sizeToFit()
        leftButton.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        let containView = UIView(frame: leftButton.bounds)
        containView.addSubview(leftButton)
        return UIBarButtonItem(customView: containView)
    }
    // MARK: - 设置选中
    class func itemWithCustomView(imageNor: String, imageSel: String, target: AnyObject?, action: Selector) -> UIBarButtonItem {
        
        let leftButton = UIButton(type:.Custom);
        leftButton.setImage(UIImage(named: imageNor), forState: .Normal)
        leftButton.setImage(UIImage(named: imageSel), forState: .Selected)
        leftButton.sizeToFit()
        leftButton.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        let containView = UIView(frame: leftButton.bounds)
        containView.addSubview(leftButton)
        return UIBarButtonItem(customView: containView)
    }
    // MARK: - 选中高亮 
    class func backItemWithCustomView(imageNor: String, imageHigh: String, target: AnyObject?, action: Selector, title: String) -> UIBarButtonItem {
        
        let backButton = UIButton(type: .Custom)
        backButton.setTitle(title, forState: .Normal)
        backButton.setTitleColor(UIColor.blackColor(), forState: .Normal)
        backButton.setTitleColor(UIColor.redColor(), forState: .Highlighted)
        backButton.setImage(UIImage(named: imageNor), forState: .Normal)
        backButton.setImage(UIImage(named: imageHigh), forState: .Highlighted)
        backButton.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        backButton.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0)
        backButton.sizeToFit()
        return UIBarButtonItem(customView: backButton)
        
    }}
